home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Testing & Debugging / Audit / Src / AuditFileDialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-21  |  6.9 KB  |  316 lines  |  [TEXT/KAHL]

  1. /*                                AuditFileDialog.c                                */
  2. /*
  3.  * AuditFileDialog.c
  4.  * Copyright © 1992-93, Apple Computer Inc. All Rights Reserved.
  5.  * Programmed by Martin Minow,
  6.  *    Internet:    minow@apple.com
  7.  *    AppleLink:    MINOW
  8.  * Version of January 22, 1993
  9.  *
  10.  * File Dialog for Audit display. This replaces the SFPutFile dialog, adding a
  11.  * TextEdit field for the Audit Selector and a checkbox for "initially enabled."
  12.  * See Inside Mac Files (3-21) for details.
  13.  *
  14.  * Edit History
  15.  *    93.01.14 MM        First public release
  16.  *    93.07.09 MM        Reformatted for 80-column page. Added a TextEdit field for
  17.  *                    the number of lines to remember in the display log.
  18.  */
  19. #include "DisplayAudit.h"
  20. #include <StandardFile.h>
  21.  
  22. /*
  23.  * Standard File dialog items. This follows the layout of the old Standard File
  24.  * (-3999) DITL. Our private items are at the end.
  25.  */
  26. enum {
  27.     kSFSaveButton = 1,
  28.     kSFCancelButton,
  29.     kSFSaveAsStaticText,
  30.     kSFVolumeUser,
  31.     kSFEjectButton,
  32.     kSFDriveButton,
  33.     kSFFileNameTextEcit,
  34.     kSFFileListUser,
  35.     kSFItemSelectorTextEdit,
  36.     kSFItemSelectorStaticText,
  37.     kSFItemAuditRecordsTextEdit,
  38.     kSFItemAuditRecordsStaticText,
  39.     kSFItemLogLinesTextEdit,
  40.     kSFItemLogLinesStaticText,
  41.     kSFItemEnabledCheckBox,
  42.     kSFItemFontPopupMenu,
  43.     kSFItemFontSizePopupMenu
  44. };
  45. enum {
  46.     kFirstTime            = -1    /* the first time our hook it's passed a -1        */
  47. };
  48.  
  49. static pascal short            PutDialogFilter(
  50.         short                    itemHit,
  51.         DialogPtr                theDialog
  52.     );
  53.  
  54. /*
  55.  * AuditFileDialog updates the global parameter resource.
  56.  */
  57. void
  58. AuditFileDialog(
  59.         short                            dialogID,
  60.         ConstStr255Param                promptString,
  61.         ConstStr255Param                originalName,
  62.         SFReply                            *reply
  63.     )
  64. {
  65.         Point                            where;
  66.         DialogTHndl                        dialogHdl;
  67.         Rect                            box;
  68.  
  69.         /*
  70.          * Center the dialog
  71.          */
  72.         dialogHdl = (DialogTHndl) GetResource('DLOG', dialogID);
  73.         if (dialogHdl == NULL) {                        /* No resource!            */
  74.             Failure(resNotFound, kErrCreateAuditRecord);
  75.             SetPt(&where, 80, 80);
  76.         }
  77.         else {
  78.             box = (**dialogHdl).boundsRect;                /* Dialog shape            */
  79.             ReleaseResource((Handle) dialogHdl);
  80.             where.h =
  81.                 (width(qd.screenBits.bounds) - width(box)) / 2;
  82.             where.v = 
  83.                 ((height(qd.screenBits.bounds) - GetMBarHeight()) / 3)
  84.                 + GetMBarHeight()
  85.                 - (height(box) / 3);
  86.         }
  87.         SFPPutFile(
  88.             where,
  89.             promptString,
  90.             originalName,
  91.             (DlgHookProcPtr) PutDialogFilter,    /* Dialog item filter            */
  92.             reply,
  93.             dialogID,
  94.             NULL                                /* No Modal Dialog Filter        */
  95.         );
  96.         gParameterUpdateNeeded = TRUE;
  97. }
  98.  
  99. static pascal short
  100. PutDialogFilter(
  101.         short                        itemHit,
  102.         DialogPtr                    theDialog
  103.     )
  104. {
  105.         short                        itemType;
  106.         Handle                        itemHandle;
  107.         Rect                        itemRect;
  108.         short                        i;
  109.         short                        nMenuItems;
  110.         short                        selectedSize;
  111.         short                        parmFontNum;
  112.         long                        thisFontSize;
  113.         Str255                        work;
  114.         Str15                        fontSizeText;
  115. #define DIALOG    (* ((DialogPeek) theDialog))
  116.  
  117.         switch (itemHit) {
  118.         case kFirstTime:
  119.             /*
  120.              * Copy the audit selector from the global storage to the dialog item.
  121.              */
  122.             work[0] = 4;
  123.             BlockMove(&PARM.auditIdent, &work[1], 4);
  124.             for (i = 1; i <= 4; i++) {
  125.                 if (work[i] < ' ') {
  126.                     work[0] = i - 1;
  127.                     break;
  128.                 }
  129.             }
  130.             GetDItem(
  131.                 theDialog,
  132.                 kSFItemSelectorTextEdit,
  133.                 &itemType,
  134.                 &itemHandle,
  135.                 &itemRect
  136.             );
  137.             SetIText(itemHandle, work);
  138.             /*
  139.              * Set the log records field.
  140.              */
  141.             GetDItem(
  142.                 theDialog,
  143.                 kSFItemAuditRecordsTextEdit,
  144.                 &itemType,
  145.                 &itemHandle,
  146.                 &itemRect
  147.             );
  148.             NumToString(PARM.auditRecords, work);
  149.             SetIText(itemHandle, work);
  150.             /*
  151.              * Set the log display lines field.
  152.              */
  153.             GetDItem(
  154.                 theDialog,
  155.                 kSFItemLogLinesTextEdit,
  156.                 &itemType,
  157.                 &itemHandle,
  158.                 &itemRect
  159.             );
  160.             NumToString(PARM.logDisplayLines, work);
  161.             SetIText(itemHandle, work);
  162.             /*
  163.              * Set the checkbox status.
  164.              */
  165.             GetDItem(
  166.                 theDialog,
  167.                 kSFItemEnabledCheckBox,
  168.                 &itemType,
  169.                 &itemHandle,
  170.                 &itemRect
  171.             );
  172.             SetCtlValue((ControlHandle) itemHandle, PARM.enableAudit);
  173.             /*
  174.              * Set the font name popup menu
  175.              */
  176.             nMenuItems = CountMItems(gFontMenu);
  177.             for (i = 1; i <= nMenuItems; i++) {
  178.                 GetItem(gFontMenu, i, work);
  179.                 if (EqualString(work, PARM.fontName, FALSE, FALSE))
  180.                     break;
  181.             }
  182.             if (i <= nMenuItems) {
  183.                 GetDItem(
  184.                     theDialog,
  185.                     kSFItemFontPopupMenu,
  186.                     &itemType,
  187.                     &itemHandle,
  188.                     &itemRect
  189.                 );
  190.                 SetCtlValue((ControlHandle) itemHandle, i);
  191.             }
  192.             /*
  193.              * Set the font size popup menu
  194.              */
  195.             GetFNum(PARM.fontName, &parmFontNum);
  196.             nMenuItems = CountMItems(gFontSizeMenu);
  197.             NumToString(PARM.fontSize, fontSizeText);
  198.             selectedSize = 0;
  199.             for (i = 1; i <= nMenuItems; i++) {
  200.                 GetItem(gFontSizeMenu, i, work);
  201.                 if (EqualString(work, fontSizeText, FALSE, FALSE))
  202.                     selectedSize = i;
  203.                 StringToNum(work, &thisFontSize);
  204.                 if (RealFont(parmFontNum, thisFontSize))
  205.                     SetItemStyle(gFontSizeMenu, i, outline);
  206.             }
  207.             if (selectedSize != 0) {
  208.                 GetDItem(
  209.                     theDialog,
  210.                     kSFItemFontSizePopupMenu,
  211.                     &itemType,
  212.                     &itemHandle,
  213.                     &itemRect
  214.                 );
  215.                 SetCtlValue((ControlHandle) itemHandle, selectedSize);
  216.             }
  217.             break;
  218.         case kSFItemEnabledCheckBox:
  219.             GetDItem(
  220.                 theDialog,
  221.                 kSFItemEnabledCheckBox,
  222.                 &itemType,
  223.                 &itemHandle,
  224.                 &itemRect
  225.             );
  226.             SetCtlValue(
  227.                 (ControlHandle) itemHandle,
  228.                 1 - GetCtlValue((ControlHandle) itemHandle)
  229.             );
  230.             break;
  231.         case kSFSaveButton:
  232.         case kSFCancelButton:
  233.             /*
  234.              * Exit: get the audit selector, even if the user hit the "Cancel"
  235.              * button. SFPPutFile will still return reply->good == FALSE if the
  236.              * file isn't to be created.
  237.              */
  238.             GetDItem(
  239.                 theDialog,
  240.                 kSFItemSelectorTextEdit,
  241.                 &itemType,
  242.                 &itemHandle,
  243.                 &itemRect
  244.             );
  245.             GetIText(itemHandle, work);
  246.             PARM.auditIdent = 0;
  247.             for (i = work[0] + 1; i <= 4; i++)
  248.                 work[i] = 0;
  249.             if (work[0] != 4)
  250.                 work[0] = 4;
  251.             BlockMove(&work[1], &PARM.auditIdent, 4);
  252.             /*
  253.              * Get the number of log records.
  254.              */
  255.             GetDItem(
  256.                 theDialog,
  257.                 kSFItemLogLinesTextEdit,
  258.                 &itemType,
  259.                 &itemHandle,
  260.                 &itemRect
  261.             );
  262.             GetIText(itemHandle, work);
  263.             StringToNum(work, &PARM.auditRecords);
  264.             /*
  265.              * Get the number of lines.
  266.              */
  267.             GetDItem(
  268.                 theDialog,
  269.                 kSFItemAuditRecordsTextEdit,
  270.                 &itemType,
  271.                 &itemHandle,
  272.                 &itemRect
  273.             );
  274.             GetIText(itemHandle, work);
  275.             StringToNum(work, &PARM.logDisplayLines);
  276.             /*
  277.              * Get the checkbox status.
  278.              */
  279.             GetDItem(
  280.                 theDialog,
  281.                 kSFItemEnabledCheckBox,
  282.                 &itemType,
  283.                 &itemHandle,
  284.                 &itemRect
  285.             );
  286.             PARM.enableAudit = GetCtlValue((ControlHandle) itemHandle);
  287.             /*
  288.              * Get the font name
  289.              */
  290.             GetDItem(
  291.                 theDialog,
  292.                 kSFItemFontPopupMenu,
  293.                 &itemType,
  294.                 &itemHandle,
  295.                 &itemRect
  296.             );
  297.             i = GetCtlValue((ControlHandle) itemHandle);
  298.             GetItem(gFontMenu, i, PARM.fontName);
  299.             /*
  300.              * Get the font size
  301.              */
  302.             GetDItem(
  303.                 theDialog,
  304.                 kSFItemFontSizePopupMenu,
  305.                 &itemType,
  306.                 &itemHandle,
  307.                 &itemRect
  308.             );
  309.             i = GetCtlValue((ControlHandle) itemHandle);
  310.             GetItem(gFontSizeMenu, i, work);
  311.             StringToNum(work, &PARM.fontSize);
  312.         }
  313.         return (itemHit);
  314. }        
  315.  
  316.